package com.sun.blog.sunblog.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.sun.blog.sunblog.model.User;
import com.sun.blog.sunblog.service.UserService;

/**
 * @author Administrator
 * @date 2013-2-1 &#x4e0b;&#x5348;4:38:40
 */
@Controller
public class LoginController {

    @Autowired
    protected UserService userService;

    /**
     * 所有默认的请求处理
     * @return
     * @Adder by Administrator 2013-2-5 上午10:06:38
     */
    @RequestMapping(value = "toLogin")
    public String defaul() {
        return "user_login";
    }

    /**
     * 用户登录
     *
     * @param name
     * @param password
     * @return
     * @Adder by Administrator 2013-2-5 下午12:02:19
     */
    @RequestMapping(value = "dologin")
    public String userLogin(@RequestParam String name, @RequestParam String password, HttpSession session) {
        User user = userService.findUserByEmail(name);
        if(null !=  user){
            if (user.getEmail().equals(name) && user.getPassword().equals(password)) {
                session.setAttribute("user", user);
                return "redirect:/backManage.htm";
            }
        }
        return "user_login";
    }

}
